package com.cyzy.controller;

import com.cyzy.dto.Result;
import com.cyzy.pojo.CampusOrder;
import com.cyzy.pojo.Wallet;
import com.cyzy.service.CampusOrderService;
import com.cyzy.service.WalletService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/campusOrder")
public class WalletController {

    @Autowired
    private WalletService walletService;

    @GetMapping("/walletById")
    public Result walletById(@Param("id") Integer id) {

        List<Wallet> wallets = walletService.selectById(id);

        if (wallets.isEmpty()) {
            return Result.error().message("没有找到对应的用户: " + id);
        }

        return Result.ok().data("wallet", wallets.get(0));
    }

}
